﻿using Hardcodet.Wpf.TaskbarNotification;
using System.Windows;

namespace RemoteCommands
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = new MainViewModel(_ShowHide);
            App.TrayIcon.DataContext = DataContext;

            this.StateChanged += (_, __) => _ShowHide(false);
        }

        private void _ShowHide(bool shoudForceHide)
        {
            if (Visibility == System.Windows.Visibility.Visible || shoudForceHide)
                this.Hide();
            else
                this.Show();
        }
    }

    public static class ext
    {
        public static T CloneObject<T>(this T obj) where T : class
        {
            if (obj == null) return null;
            System.Reflection.MethodInfo inst = obj.GetType().GetMethod("MemberwiseClone",
                System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            if (inst != null)
                return (T)inst.Invoke(obj, null);
            else
                return null;
        }
    }
}
